package com.zhangshuo.patternDesign.strategy.common;

/**
 * Created by shuo.zhang on 2017-10-22.
 *
 * 消费者类
 *
 */
public class Custom {
    /**
     * 总计金额
     */
    private Double totalAmount = 0D;

    public Double getAmount() {
        return amount;
    }

    public Double getTotalAmount() {
        return totalAmount;
    }

    /**
     * 本次消费金额
     */
    private Double amount;


    private PriceStrategy priceStrategy;

    /**
     * 设置策略,将判定的条件加入到工厂方法中
     * @param price
     */
    private void registerStrategy(Double price){
        this.priceStrategy = StrategyFactory.instance().createStrategy(this);


    }


    /**
     * 结算折扣
     * @param price
     * @return
     */
    public double calLastAmount(Double price){
        registerStrategy(price);
        this.amount = price;
        Double calAmount =  priceStrategy.calPrice(amount);
        totalAmount += calAmount;
        return calAmount;
    }

}
